package cn.ybx.seaIslands.models;

public class RectangleSeaIslandsMap extends SeaIslandsMap {
    private int width;
    private int heigth;
    private char[][] gridMap;

    public RectangleSeaIslandsMap(char[][] gridMap) {
        this.gridMap = gridMap;
        this.width = gridMap[0].length;
        this.heigth = gridMap.length;
    }

    @Override
    public double getMapArea() {
        return width * heigth;
    }

    @Override
    public boolean isInsideTheMap(Point thePoint) {
        return thePoint.getLantitude() >= 0 && thePoint.getLantitude() < heigth
                && thePoint.getLongitude() >= 0 && thePoint.getLongitude() < width;
    }

    @Override
    public Island findIslandByCoordinates(Point thePoint) {
        for (Island island : this.getIslands()) {
            if (island.getLandCoordinates().contains(thePoint)) {
                return island;
            }
        }
        return null;
    }

}
